#include "BondDetailBroker.h"
#include "DetailQuoteTable.h"
#include "BondDetailData.h"
#include "BondDetailBrokerBestPrice.h"
#include "BondDetailPrcInter.h"
#include <QStylePainter>
#include <core/StyleMgr.h>
#include <QVBoxLayout>

BondDetailBroker::BondDetailBroker(QWidget* p)
    : QWidget(p)
{

}

void BondDetailBroker::onBondChanged()
{
	m_data->reqMarketStream(0);
	m_table->update();
}

bool BondDetailBroker::setBrokerTab(int nBrokerId)
{
	if (m_brokerTab->isShowTab())
	{
		m_brokerTab->update(nBrokerId);
		return true;
	}
	else
	{
		return false;
	}
}

void BondDetailBroker::setDetailData(QSharedPointer<DetailData> data)
{
    m_data=data;

    QVBoxLayout* l = new QVBoxLayout();
    l->setContentsMargins(0, 0, 0, 0);
    l->setSpacing(4);
    setLayout(l);

    m_brokerTab = new BrokerBestPrice(this, m_data);
    l->addWidget(m_brokerTab);

    m_table = new DetailQuoteTable(this, m_data, DETAILOTHERTYPE_BROKER);
    l->addWidget(m_table);

    BondDetailPrcInter* m_prcInter = new BondDetailPrcInter(this);
    m_prcInter->setDetailData(m_data);
    m_prcInter->setFixedHeight(40);

    l->addWidget(m_prcInter);

    connect(m_data.get(), &DetailData::bondChanged, this, &BondDetailBroker::onBondChanged);
}
